<?php
	if($_GET['page'] == "login.html")
		setCookie("loggedIn","false",(time()+(60*60*24)));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
  <head>
    <link href="css/style.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="bin/prototype.js"></script>
    <script type="text/javascript" src="bin/functions.js"></script>


    <title> LYON UNO </title>
  </head>

  <body>

    <div id="head_pic">
      <img src="images/title.png" alt="[LYON UNO]" id="picture">
    </div>

    <div id="webpage">
	<?php 
		$page = $_GET['page'];
		if($_GET['page'] != "login.html" && $_GET['page'] != "existingUser.html" && $_GET['page'] != "register.html" && $_GET['page'] != "privacy.html" && $_GET['page'] != "conditions.html" && $_GET['page'] != ''){
			if($_COOKIE["loggedIn"] == "false")
				$page = 'login.html';
		}
		if ( $page == '' && ($_COOKIE["loggedIn"] == "false" || $_COOKIE["loggedIn"] == "") )
			$page = 'login.html';
		if ( $page == '' && $_COOKIE["loggedIn"] != "false"){

echo "<table border = 1>";
echo "<tr>";
echo "<td>";
echo "<ul> <li><a href=\"main.php?page=login.html\" > Logout</a></li>";
echo "<br>";
echo "<li><a href=\"http://en.wikipedia.org/wiki/Uno_(game)\" > Read the rules</a></li>";
echo "<br>";
echo "<li><a href=\"ranking.php\"> See the ranking</a></li>";
echo "<br>";
echo "<li><a href=\"profile.php\"> Change profile</a></li>";
echo "<br>";
echo "<li><a href=\"users.php\"> See LYON UNO user's profiles</a></li>";
echo "<br>";
echo "<li><a href=\"createGame.php\"> Create game</a></li>";
echo "<br>";
echo "<li><a href=\"invitations.php\"> Received invitations</a></li>";
echo "<br>";
echo "<li><a href=\"main.php?page=mapSite.html\"> Site map</a></li> </ul>";
echo "</td>";
echo "<td>";
echo "<img src = \"images/greenbar.png\"";
echo "</td>";
echo "<td>";
$hostDB = "localhost";
$userDB = "ampersand";
$passDB = "palomitas";
$dbnameDB = "LYONUNO";

$canalDB = mysql_connect($hostDB, $userDB, $passDB);
$db = mysql_select_db($dbnameDB);
$consulta = 'select name from GAME where public_game = \'y\' and nick3_in = \'n\' order by name asc';

$resDB = mysql_db_query($dbnameDB, $consulta,$canalDB);

echo "<table border = 3>";
echo "<tr><td><h3> List of available games </h3></td>";
while($row = mysql_fetch_object($resDB)){
	$name = $row->name;
	echo "<tr><td><a href=\"waiting.php?game=".$name."\">" . $name ."<a></td></tr>";
}
echo "</table>";
mysql_free_result($resDB);
mysql_close($canalDB);
echo "</td>";
echo "</tr>";
echo "</table>";
}else{

		$Lines = file($page);
		foreach($Lines as $Key => $Line) {
			$LineNum = $Key + 1;
			echo $Line;
		}
}
	?>
    </div>

    <div id="foot">
      <address>LYON UNO. CPE <br> 43, boulevard du 11 Novembre 1918. BP 2077 <br> 69616 Villeurbanne Cedex </address>
    </div>
  </body>
</html>
